﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class ContactUsCls
    {
        public string ContactUsId;
        public string FullName;
        public string Email;
        public string PhoneNumber;
        public string Address;
        public string Title;
        public string Body;
        public DateTime EntryDate;
        public DateTime ReadDate;
        public int HasRead;
        public string ReadBy = "";
    }

    public class ContactUsParser
    {
        public static ContactUsCls CreateInstance()
        {
            //tao 1 class trang....
            ContactUsCls oContactUsCls = new ContactUsCls();
            return oContactUsCls;
        }

        public static ContactUsCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            ContactUsCls oContactUsCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oContactUsCls;
        }


        public static ContactUsCls ParseFromDataRow(DataRow dr)
        {
            ContactUsCls oContactUsCls = new ContactUsCls();
            oContactUsCls.ContactUsId = XmlUtility.GetString(dr, "ContactUsId", true);
            oContactUsCls.FullName = XmlUtility.GetString(dr, "FullName", true);
            oContactUsCls.Email = XmlUtility.GetString(dr, "Email", true);
            oContactUsCls.Address = XmlUtility.GetString(dr, "Address", true);
            oContactUsCls.Title = XmlUtility.GetString(dr, "Title", true);
            oContactUsCls.Body = XmlUtility.GetString(dr, "Body", true);
            oContactUsCls.EntryDate = XmlUtility.GetDate(dr, "EntryDate", true);
            oContactUsCls.ReadDate = XmlUtility.GetDate(dr, "ReadDate", true);
            oContactUsCls.ReadBy = XmlUtility.GetString(dr, "ReadBy", true);
            oContactUsCls.HasRead = XmlUtility.GetInt(dr, "HasRead", true);
            oContactUsCls.PhoneNumber = XmlUtility.GetString(dr, "PhoneNumber", true);
            return oContactUsCls;
        }

        public static ContactUsCls[] ParseFromDataTable(DataTable dtTable)
        {
            ContactUsCls[] ContactUss = new ContactUsCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                ContactUss[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return ContactUss;
        }

        public static ContactUsCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new ContactUsCls[0];
            }
            ContactUsCls[] ContactUss = new ContactUsCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                ContactUss[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return ContactUss;
        }
    }
}
